<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="工具,前端开发,node,调试," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="node程序的调试向来是比较令人头疼的问题，不过Chrome DevTools在去年已经可以支持node程序的调试，虽然不像使用Eclipse调试Java程序那么方便功能那么强大，但是也算是提供了一个便捷的途径来帮助我们快速的定位node程序的问题。
这个功能是在Google I/O 2016上正式发布的，可以通过这里的视频(youtube，需翻墙)了解更多信息。

使用步骤记录如下：
安装最新的">
<meta property="og:type" content="article">
<meta property="og:title" content="使用Chrome DevTools单步调试node程序">
<meta property="og:url" content="http://jiji262.github.io/2017/02/19/node-debug-with-chrome/index.html">
<meta property="og:site_name" content="令狐葱@前端笔记">
<meta property="og:description" content="node程序的调试向来是比较令人头疼的问题，不过Chrome DevTools在去年已经可以支持node程序的调试，虽然不像使用Eclipse调试Java程序那么方便功能那么强大，但是也算是提供了一个便捷的途径来帮助我们快速的定位node程序的问题。
这个功能是在Google I/O 2016上正式发布的，可以通过这里的视频(youtube，需翻墙)了解更多信息。

使用步骤记录如下：
安装最新的">
<meta property="og:image" content="https://cdn-images-1.medium.com/max/1600/1*iHurZ1VUsM54zGjZJHqexQ.png">
<meta property="og:updated_time" content="2017-02-20T09:11:01.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用Chrome DevTools单步调试node程序">
<meta name="twitter:description" content="node程序的调试向来是比较令人头疼的问题，不过Chrome DevTools在去年已经可以支持node程序的调试，虽然不像使用Eclipse调试Java程序那么方便功能那么强大，但是也算是提供了一个便捷的途径来帮助我们快速的定位node程序的问题。
这个功能是在Google I/O 2016上正式发布的，可以通过这里的视频(youtube，需翻墙)了解更多信息。

使用步骤记录如下：
安装最新的">
<meta name="twitter:image" content="https://cdn-images-1.medium.com/max/1600/1*iHurZ1VUsM54zGjZJHqexQ.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"post","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jiji262.github.io/2017/02/19/node-debug-with-chrome/"/>





  <title> 使用Chrome DevTools单步调试node程序 | 令狐葱@前端笔记 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?0fd825270d7f51597f963010828c65b8";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>










  
  
    
  

  <div class="container one-collumn sidebar-position-post page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">令狐葱@前端笔记</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle"></p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://jiji262.github.io/2017/02/19/node-debug-with-chrome/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="令狐葱">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="令狐葱@前端笔记">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="令狐葱@前端笔记" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                使用Chrome DevTools单步调试node程序
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-02-19T20:10:00+08:00">
                2017-02-19
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/02/19/node-debug-with-chrome/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2017/02/19/node-debug-with-chrome/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>node程序的调试向来是比较令人头疼的问题，不过Chrome DevTools在去年已经可以支持node程序的调试，虽然不像使用Eclipse调试Java程序那么方便功能那么强大，但是也算是提供了一个便捷的途径来帮助我们快速的定位node程序的问题。</p>
<p>这个功能是在Google I/O 2016上正式发布的，可以通过<a href="https://youtu.be/x8u0n4dT-WI?t=2571" target="_blank" rel="external">这里的视频</a>(youtube，需翻墙)了解更多信息。</p>
<p><img src="https://cdn-images-1.medium.com/max/1600/1*iHurZ1VUsM54zGjZJHqexQ.png" alt=""></p>
<p>使用步骤记录如下：</p>
<h1 id="安装最新的Node"><a href="#安装最新的Node" class="headerlink" title="安装最新的Node"></a>安装最新的Node</h1><p>要支持这项功能，需要node.js的版本在6.3.0以上。如果版本较低，将会提示不支持该功能。在Mac上你可以使用nvm来切换node的版本，具体请自行google之。</p>
<figure class="highlight x86asm"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">➜  wx node --inspect --debug-brk index.js</div><div class="line"><span class="symbol">node:</span> bad <span class="meta">option</span>: --inspect</div><div class="line">➜  wx node -v</div><div class="line">v6<span class="meta">.2</span><span class="meta">.0</span></div><div class="line">➜  wx nvm list</div><div class="line">-&gt;       v6<span class="meta">.2</span><span class="meta">.0</span></div><div class="line">         v7<span class="meta">.3</span><span class="meta">.0</span></div><div class="line"><span class="meta">default</span> -&gt; <span class="number">6.2</span> (-&gt; v6<span class="meta">.2</span><span class="meta">.0</span>)</div><div class="line">node -&gt; stable (-&gt; v7<span class="meta">.3</span><span class="meta">.0</span>) (<span class="meta">default</span>)</div><div class="line">stable -&gt; <span class="number">7.3</span> (-&gt; v7<span class="meta">.3</span><span class="meta">.0</span>) (<span class="meta">default</span>)</div><div class="line">iojs -&gt; N/A (<span class="meta">default</span>)</div><div class="line">➜  wx nvm use <span class="number">7.3</span><span class="meta">.0</span></div><div class="line">Now using node v7<span class="meta">.3</span><span class="meta">.0</span> (npm v3<span class="meta">.10</span><span class="meta">.10</span>)</div></pre></td></tr></table></figure>
<h1 id="运行node程序"><a href="#运行node程序" class="headerlink" title="运行node程序"></a>运行node程序</h1><p>运行node程序时需要带上<code>--inspect</code>标记。比如可以这样运行：<br><figure class="highlight crmsh"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">node</span> <span class="title">--inspect</span> index.js</div></pre></td></tr></table></figure></p>
<p>如果需要在node程序的第一行就自动加断点，可以这样来执行：<br><figure class="highlight crmsh"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">node</span> <span class="title">--inspect</span> --debug-brk index.js</div></pre></td></tr></table></figure></p>
<h1 id="打开调试连接"><a href="#打开调试连接" class="headerlink" title="打开调试连接"></a>打开调试连接</h1><p>执行之后就会看到一个<code>chrome-devtools://...</code>开头的链接，然后复制到Chrome浏览器中，就可以进行node程序的调试了。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">➜  wx node <span class="comment">--inspect --debug-brk index.js</span></div><div class="line">Debugger listening on port 9229.</div><div class="line">Warning: This is an experimental feature and could <span class="keyword">change</span> <span class="keyword">at</span> <span class="keyword">any</span> time.</div><div class="line"><span class="keyword">To</span> <span class="keyword">start</span> debugging, <span class="keyword">open</span> the <span class="keyword">following</span> <span class="keyword">URL</span> <span class="keyword">in</span> Chrome:</div><div class="line">    chrome-devtools://devtools/bundled/inspector.html?experiments=<span class="literal">true</span>&amp;v8only=<span class="literal">true</span>&amp;ws=<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9229</span>/d9c8660e-ce96<span class="number">-44</span>bb<span class="number">-9742</span><span class="number">-515</span>bf49ee26b</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        
<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/uploads/wechatmp.jpg" alt="令狐葱 wechat" style="width: 200px; max-width: 100%;"/>
    <div>欢迎您扫一扫上面的二维码，订阅我的微信公众号！</div>
</div>


      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div></div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/uploads/wechatpay.png" alt="令狐葱 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="/uploads/alipaypay.png" alt="令狐葱 Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/工具/" rel="tag"># 工具</a>
          
            <a href="/tags/前端开发/" rel="tag"># 前端开发</a>
          
            <a href="/tags/node/" rel="tag"># node</a>
          
            <a href="/tags/调试/" rel="tag"># 调试</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/11/28/introduction-to-react-flux/" rel="next" title="手把手教你玩转 React Flux">
                <i class="fa fa-chevron-left"></i> 手把手教你玩转 React Flux
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2017/02/19/node-debug-with-chrome/"
           data-title="使用Chrome DevTools单步调试node程序" data-url="http://jiji262.github.io/2017/02/19/node-debug-with-chrome/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="令狐葱" />
          <p class="site-author-name" itemprop="name">令狐葱</p>
           
              <p class="site-description motion-element" itemprop="description">去留无意，闲看庭前花开花落；宠辱不惊，漫随天外云卷云舒。</p>
          
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">28</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/jiji262" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/linghucong" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/jiji262" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#安装最新的Node"><span class="nav-number">1.</span> <span class="nav-text">安装最新的Node</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#运行node程序"><span class="nav-number">2.</span> <span class="nav-text">运行node程序</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#打开调试连接"><span class="nav-number">3.</span> <span class="nav-text">打开调试连接</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">令狐葱</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"jiji262"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  













  
  

  

  

  

  


</body>
</html>
